package com.neu.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.neu.system.domain.NeuAir;
import com.neu.system.domain.vo.NeuAirVO;
import com.neu.system.service.INeuAirService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.neu.common.annotation.Log;
import com.neu.common.core.controller.BaseController;
import com.neu.common.core.domain.AjaxResult;
import com.neu.common.enums.BusinessType;
import com.neu.common.utils.poi.ExcelUtil;
import com.neu.common.core.page.TableDataInfo;

import static com.neu.common.utils.PageUtils.startPage;

/**
 * 【请填写功能名称】Controller
 *
 */
@RestController
@RequestMapping("/system/air")
@Api(tags = "空气数据")
public class NeuAirController extends BaseController
{
    @Autowired
    private INeuAirService neuAirService;

    /**
     * 查询空气数据列表
     */
    @ApiOperation("城市空气数据")
    @GetMapping("/list")
    public TableDataInfo list(NeuAir neuAir)
    {
        startPage();
        List<NeuAirVO> list = neuAirService.selectNeuAirList(neuAir);

        TableDataInfo dataTable = getDataTable(list);
        Long total = neuAirService.selectCount(neuAir);
        dataTable.setTotal(total);
        return dataTable;
    }

    /**
     * 导出空气数据列表
     */
    @ApiOperation("导出空气数据Excel")
    @Log(title = "导出空气数据Excel", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NeuAir neuAir)
    {
        List<NeuAirVO> list = neuAirService.selectNeuAirList(neuAir);
        ExcelUtil<NeuAirVO> util = new ExcelUtil<NeuAirVO>(NeuAirVO.class);
        util.exportExcel(response, list, "空气数据数据");
    }

    /**
     * 获取数据详细信息
     */
    @ApiOperation("获取详情数据")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(neuAirService.selectNeuAirById(id));
    }

    /**
     * 新增空气数据
     */
    @ApiOperation("新增空气数据")
    @PreAuthorize("@ss.hasPermi('system:air:add')")
    @Log(title = "新增空气数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NeuAir neuAir)
    {
        return AjaxResult.success(neuAirService.insertNeuAir(neuAir));
    }

    /**
     * 修改历史数据
     */
    @ApiOperation("修改历史数据")
    @PreAuthorize("@ss.hasPermi('system:air:edit')")
    @Log(title = "修改历史数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NeuAir neuAir)
    {
        return toAjax(neuAirService.updateNeuAir(neuAir));
    }

    /**
     * 删除历史数据
     */
    @ApiOperation("删除历史数据")
    @PreAuthorize("@ss.hasPermi('system:air:remove')")
    @Log(title = "删除历史数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(neuAirService.deleteNeuAirByIds(ids));
    }
}
